class BooksController < ApplicationController
  # GET /books
  # GET /books.xml
  def index
    @books = Book.all
  end

  # GET /books/1
  # GET /books/1.xml
  def show
    @book = Book.find(params[:id])
  end

  # GET /books/new
  # GET /books/new.xml
  def new
    @book = Book.new
    @courses = Course.all.collect{|x| [x.name,x.id]}
  end

  # GET /books/1/edit
  def edit
    @book = Book.find(params[:id])
    @courses = Course.all.collect{|x| [x.name,x.id]}
  end

  # POST /books
  # POST /books.xml
  def create
    @book = Book.new(params[:book])
    if @book.save
      redirect_to(:action => "index", :notice => 'Book was successfully created.')
    else
      render :action => "new"
    end
  end

  # PUT /books/1
  # PUT /books/1.xml
  def update
    @book = Book.find(params[:id])
    if @book.update_attributes(params[:book])
      redirect_to :action => 'index', :notice => 'Book was successfully updated.'
    else
      render :action => "edit"
    end
  end

  # DELETE /books/1
  # DELETE /books/1.xml
  def destroy
    @book = Book.find(params[:id])
    @book.destroy

    redirect_to :action => 'index'
  end
end
